package com.shyroke.daydayzhuanapi.mapper;

import com.shyroke.daydayzhuanapi.dto.SpiderInfoDto;
import com.shyroke.daydayzhuanapi.entity.SpiderInfoEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SpiderInfoMapper {
    @Autowired
    private ModelMapper modelMapper;

    public SpiderInfoDto entityToDto(SpiderInfoEntity e) {
        SpiderInfoDto dto = new SpiderInfoDto();
        dto.setSiteName(e.getSiteName());
        dto.setSiteUrl(e.getSiteUrl());
        dto.setAutoSave(e.getAutoSave());
        dto.setTypeId(e.getTypeId());
        dto.setIsMachine(e.getIsMachine());
        dto.setArticleelecssquery(e.getArticleEleCssQuery());
        dto.setTodayformat(e.getTodayFormat());
        dto.setDatecssquery(e.getDateCssQuery());
        dto.setTitlecssquery(e.getTitleCssQuery());
        dto.setUrlcssquery(e.getUrlCssQuery());
        dto.setDesccssquery(e.getDescCssQuery());
        dto.setDescexcludecssquery(e.getDescExcludeCssQuery());
        dto.setDescurlpre(e.getDescUrlPre());
        dto.setDateignore(e.getDateIgnore());
        dto.setId(e.getId());
        return dto;
    }

    public SpiderInfoEntity dtoToEntity(SpiderInfoDto spiderInfo) {
        SpiderInfoEntity entity = new SpiderInfoEntity();
        entity.setSiteName(spiderInfo.getSiteName());
        entity.setSiteUrl(spiderInfo.getSiteUrl());
        entity.setAutoSave(spiderInfo.getAutoSave());
        entity.setTypeId(spiderInfo.getTypeId());
        entity.setIsMachine(spiderInfo.getIsMachine());
        entity.setArticleEleCssQuery(spiderInfo.getArticleelecssquery());
        entity.setTodayFormat(spiderInfo.getTodayformat());
        entity.setDateCssQuery(spiderInfo.getDatecssquery());
        entity.setTitleCssQuery(spiderInfo.getTitlecssquery());
        entity.setUrlCssQuery(spiderInfo.getUrlcssquery());
        entity.setDescCssQuery(spiderInfo.getDesccssquery());
        entity.setDescExcludeCssQuery(spiderInfo.getDescexcludecssquery());
        entity.setDescUrlPre(spiderInfo.getDescurlpre());
        entity.setDateIgnore(spiderInfo.getDateignore());
        if(spiderInfo.getId() != null){
            entity.setId(spiderInfo.getId());
        }
        return entity;
    }
}
